
// import  "./mod/sportwork";
/**
 *
 * 数据格式
 */

// 学生信息
// const data_students = [
//   { name: "陈博文", id: "2024026135" },
//   { name: "扈嘉莉", id: "2024026136" },
//   { name: "姜壮", id: "2024026137" },
//   { name: "李鑫源", id: "2024026138" },
//   { name: "包晨阳", id: "2024026139" },
//   { name: "张晨蕾", id: "2024026140" },
//   { name: "王航博", id: "2024026141" },
//   { name: "王鑫宇", id: "2024026142" },
//   { name: "赵佳玮", id: "2024026143" },
//   { name: "李泽", id: "2024026144" },
//   { name: "郭佳鹏", id: "2024026145" },
//   { name: "盖梦璇", id: "2024026146" },
//   { name: "高明轩", id: "2024026147" },
//   { name: "达恩迪", id: "2024026148" },
//   { name: "刘艺坤", id: "2024026149" },
//   { name: "马超", id: "2024026150" },
//   { name: "沈侃", id: "2024026151" },
//   { name: "刘玉龙", id: "2024026152" },
//   { name: "赵怡珂", id: "2024026153" },
//   { name: "李岩154", id: "2024026154" },
//   { name: "李文慧", id: "2024026155" },
//   { name: "徐嘉晨", id: "2024026156" },
//   { name: "吴欣苹", id: "2024026157" },
//   { name: "刘鑫圆", id: "2024026158" },
//   { name: "李岩159", id: "2024026159" },
//   { name: "李永恩", id: "2024026160" },
//   { name: "孟凯", id: "2024026161" },
//   { name: "刘诺琳", id: "2024026162" },
//   { name: "王博颖", id: "2024026163" },
//   { name: "任涛", id: "2024026164" },
//   { name: "郝晨光", id: "2024026165" },
//   { name: "杜瑞扬", id: "2024026166" },
//   { name: "李泽裕", id: "2024026167" },
//   { name: "康琢皓", id: "2024026168" },
//   { name: "魏家豪", id: "2024026169" },
//   { name: "王可依", id: "2024026170" },
//   { name: "赵晓玉", id: "2024026171" },
//   { name: "郭泽", id: "2024026172" },
//   { name: "张爱平", id: "2024026173" },
//   { name: "蒲洪莹", id: "2024026174" },
//   { name: "于永航", id: "2024026175" },
//   { name: "石建杰", id: "2024026176" },
//   { name: "刘奎冠", id: "2024026177" },
//   { name: "周帅飞", id: "2024026178" },
//   { name: "张天宇", id: "2024026179" },
//   { name: "赵文杰", id: "2024026180" },
//   { name: "李明泽", id: "2024026181" },
//   { name: "孙冠宇", id: "2024026182" },
//   { name: "祁俊霞", id: "2024026183" },
//   { name: "吴玉龙", id: "2024026184" },
//   { name: "王玉宽", id: "2024026185" },
//   { name: "史亚熙", id: "2024026186" },
//   { name: "吴荣盛", id: "2024026187" },
//   { name: "唐博", id: "2024026188" },
//   { name: "朱泽成", id: "2024026189" },
//   { name: "张雨佳", id: "2024026190" },
//   { name: "魏源", id: "2024026191" },
//   { name: "安梦亚", id: "2024026192" },
//   { name: "曹震", id: "2024026193" },
//   { name: "苑佳旺", id: "2024026194" },
//   { name: "赵雅鹏", id: "2024026195" },
//   { name: "冉子轩", id: "2024026196" },
//   { name: "杨贺斌", id: "2024026197" },
//   { name: "陈建飞", id: "2024026198" },
//   { name: "魏国豪", id: "2024026199" },
//   { name: "郭赛奇", id: "2024026200" },
//   { name: "韩学伟", id: "2024026201" },
//   { name: "朱云航", id: "2024026202" },
//   { name: "张宝鑫", id: "2024026203" },
//   { name: "王思蘅", id: "2024026204" },
 
// ];

// 空表格式
let obj_bz = {
  // A: "人员",
  // B: "总加分",
  // C: "总加分情况",
  // D: "总减分",
  // E: "总减分情况",
  // F: "总分",
  student_number: "student_number", //学号a
  student_name: "student_name", //姓名b

  //学业
  school_work_average: "school_work_average", //平均学分c
  school_work_basic: "school_work_basic", //基础学分d
  school_work_award: "school_work_award", //本人奖励分e
  school_work_award_total: "school_work_award_total", //班级奖励分（最高）f
  school_work_award_practical: "school_work_award_practical", //本人实际奖励分g
  school_work_deduct: "school_work_deduct", //本人扣分
  school_work_total: "school_work_total", //学业总分h

  //文体
  sport_work_basic: "sport_work_basic", //基础学分j
  sport_work_award: "sport_work_award", //本人奖励分k
  sport_work_award_total: "sport_work_award_total", //班级奖励分（最高）L
  sport_work_award_practical: "sport_work_award_practical", //本人实际奖励分M
  sport_work_deduct: "sport_work_deduct", //本人扣分N
  sport_work_total: "sport_work_total", //文体总分O

  //品德

  moral_work_basic: "moral_work_basic", //基础学分Q
  moral_work_award: "moral_work_award", //本人奖励分R
  moral_work_award_total: "moral_work_award_total", //班级奖励分（最高）S
  moral_work_award_practical: "moral_work_award_practical", //本人实际奖励分 T
  moral_work_deduct: "moral_work_deduct", //本人扣分U
  moral_work_total: "moral_work_total", //品德总分V

  //能力

  ability_work_basic: "ability_work_basic", //基础学分X
  ability_work_award: "ability_work_award", //本人奖励分Y
  ability_work_award_total: "ability_work_award_total", //班级奖励分（最高）Z
  ability_work_award_practical: "ability_work_award_practical", //本人实际奖励分
  ability_work_total: "ability_work_total", //能力总分

  //最终总分
  total: "total",
};

// 保留空副本
let empty_data = { ...obj_bz };
Object.keys(empty_data).forEach((key) => {
  // 或者使用 null
  if (key != "student_number" && key != "student_name") {
    empty_data[key] = Number(0);
  } else {
    empty_data[key] = "";
  }
});

// 实际表头
let fieldKey_bz = {
  student_number: "学号",
  student_name: "姓名",

  school_work_average: "学年平均学分",
  school_work_basic: "基本分",
  school_work_award: "本人奖励分",
  school_work_award_total: "班级奖励分（最高）",
  school_work_award_practical: "本人实际奖励分",
  school_work_deduct: "本人扣分",
  school_work_total: "学业总分",

  sport_work_basic: "基本分",
  sport_work_award: "本人奖励分",
  sport_work_award_total: "班级奖励分（最高）",
  sport_work_award_practical: "本人实际奖励分",
  sport_work_deduct: "本人扣分",
  sport_work_total: "文体总分",

  moral_work_basic: "基本分",
  moral_work_award: "本人奖励分",
  moral_work_award_total: "班级奖励分（最高）",
  moral_work_award_practical: "本人实际奖励分",
  moral_work_deduct: "本人扣分",
  moral_work_total: "品德总分",

  ability_work_basic: "基本分",
  ability_work_award: "本人奖励分",
  ability_work_award_total: "班级奖励分（最高）",
  ability_work_award_practical: "本人实际奖励分",
  ability_work_total: "能力总分",

  total: "最终总分",
};

// 表数据
let fieldKey = {
  A: "日报日期",
  B: "人员",
  C: "类型",
  D: "加分项/减分项",
  E: "描述",
  F: "日报提交人",
  G: "品德项目",
  H: "品德分数",
  I: "学业项目",
  J: "学业分数",
  K: "文体项目",
  L: "文体分数",
  M: "能力项目",
  N: "能力分数",
  O: "附件",
};

// 类型定义
let type_list = [
  {
    text: "品德",
    key: "moral_work",
    value: "品德",
  },
  {
    text: "学业",
    key: "school_work",
    value: "学业",
  },
  {
    text: "文体",
    key: "sport_work",
    value: "文体",
  },
  {
    text: "能力",
    key: "ability_work",
    value: "能力",
  },
];

// 存储各类型最高峰
let type_max_list = {
  school_work: 0, // 学业
  sport_work: 0,  // 文体
  moral_work: 0,  // 品德
  ability_work: 0,// 能力
};

/**
 * 阅读指南：
 * 导出数据测试：搜索 「exportDataByUser」关键字，找到函数即可
 * 导出接口数据：搜索「exportApiDemo」关键字，找到函数即可
 * 导出复杂表头：搜索「exportExtendDemo」关键字，找到函数即可
 * 批量设置样式：搜索「exportStyleDemo」关键字，找到函数即可
 * 简单文件导入：搜索「uploadExcel」可找到导入的处理逻辑，拖拽文件/选择文件回调获取files对象请搜索「#LAY-excel-import-excel」
 * upload模块：搜索「uploadInst」查看使用逻辑，导入相关逻辑同上
 */

layui.use(
  ["jquery", "layer", "upload", "excel", "laytpl", "element", "code"],
  function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var upload = layui.upload;
    var excel = layui.excel;
    var laytpl = layui.laytpl;
    var element = layui.element;

    /**
     * 上传excel的处理函数，传入文件对象数组
     * @param  {FileList} files [description]
     * @return {[type]}       [description]
     */
    function uploadExcel(files) {
   
      try {
        excel.importExcel(
          files,
          {
            // 可以在读取数据的同时梳理数据
            fields: {
              日报日期: "A",
              人员: "B",
              类型: "C",
              "加分项/减分项": "D",
              描述: "E",
              日报提交人: "F",
              品德项目: "G",
              品德分数: "H",
              学业项目: "I",
              学业分数: "J",
              文体项目: "K",
              文体分数: "L",
              能力项目: "M",
              能力分数: "N",
              附件: "O",
            },
          },
          function (data, book) {
            // data: {1: {sheet1: [{id: 1, name: 2}, {...}]}}// 工作表的数据对象
            // book: {1: {Sheets: {}, Props: {}, ....}} // 工作表的整个原生对象，https://github.com/SheetJS/js-xlsx#workbook-object
            // 也可以全部读取出来再进行数据梳理
            /*        data = excel.filterImportData(data, {
          'id': 'A'
          , 'username': 'B'
          , 'experience': 'C'
          , 'sex': 'D'
          , 'score': 'E'
          , 'city': 'F'
          , 'classify': 'G'
          , 'wealth': 'H'
          , 'sign': 'I'
        })*/
            // 如果不需要展示直接上传，可以再次 $.ajax() 将JSON数据通过 JSON.stringify() 处理后传递到后端即可
            /**
             * 2019-06-21 JeffreyWang 应群友需求，加一个单元格合并还原转换
             * 思路：
             * 1. 渲染时为每个cell加上唯一的ID，demo里边采用 table-export-文件索引-sheet名称-行索引-列索引
             * 2. 根据 book[文件索引].Sheets[sheet名称]['!merge'] 参数，取左上角元素设置 colspan 以及 rowspan，并删除其他元素
             */
            // layer.open({
            //   title: '文件转换结果'
            //   , area: ['799px', '399px']
            //   , tipsMore: true
            //   , content: laytpl($('#LAY-excel-export-ans').html()).render({data: data, files: files})
            //   , success: function () {
            //     element.render('tab')
            //     layui.code({})
            //     // 处理合并
            //     for (var file_index in book) {
            //       if (!book.hasOwnProperty(file_index)) {
            //         continue
            //       }
            //       // 遍历每个Sheet
            //       for (var sheet_name in book[file_index].Sheets) {
            //         if (!book[file_index].Sheets.hasOwnProperty(sheet_name)) {
            //           continue
            //         }
            //         var sheetObj = book[file_index].Sheets[sheet_name]
            //         // 仅在有合并参数时进行操作
            //         if (!sheetObj['!merges']) {
            //           continue
            //         }
            //         // 遍历每个Sheet中每个 !merges
            //         for (var merge_index = 0; merge_index < sheetObj['!merges'].length; merge_index++) {
            //           var mergeObj = sheetObj['!merges'][merge_index]
            //           // 每个合并参数的 s.c 表示左上角单元格的列，s.r 表示左上角单元格的行，e.c 表示右下角单元格的列，e.r 表示右下角单元格的行，计算时注意 + 1
            //           $('#table-export-' + file_index + '-' + sheet_name + '-' + mergeObj.s.r + '-' + mergeObj.s.c)
            //             .prop('rowspan', mergeObj.e.r - mergeObj.s.r + 1)
            //             .prop('colspan', mergeObj.e.c - mergeObj.s.c + 1)
            //           for (var r = mergeObj.s.r; r <= mergeObj.e.r; r++) {
            //             for (var c = mergeObj.s.c; c <= mergeObj.e.c; c++) {
            //               // 排除左上角
            //               if (r === mergeObj.s.r && c === mergeObj.s.c) {
            //                 continue
            //               }
            //               $('#table-export-' + file_index + '-' + sheet_name + '-' + r + '-' + c).remove()
            //             }
            //           }
            //         }
            //       }
            //     }
            //   }
            // })

            // 表名
            let data_fie = "工作日报";
            console.log(data[0], data[0][data_fie]);
            // 创建一个变量接受data[0]['工作日报']
            let data_list = data[0][data_fie];

  


            // 建立空数组
            let data_list_new = [];
            let title = { ...empty_data };
            title.student_number = "综合测评加减分";
            data_list_new.push(title);

            title = { ...empty_data };
            title.student_number =
              "综合测评成绩=品德表现测评分X0.15+学业测评得分X0.65+文体测评得分X0.1+能力测评得分X0.1";
            data_list_new.push(title);

            title = { ...empty_data };
            title.school_work_average = "学业表现0.65";
            title.sport_work_basic = "文体表现0.1";
            title.moral_work_basic = "品德表现0.15";
            title.ability_work_basic = "能力表现0.1";
            data_list_new.push(title);


            title = { ...empty_data };
            title.school_work_average = `学业表现测评得分=基本分+奖励分-扣分
基本分=本人学年平均学分绩*0.9
奖励分=本人奖励分/班级奖励最高分*100*0.1 `;
            title.sport_work_basic = `文体表现测评得分=基本分+奖励分-扣分 
奖励分=本人奖励分/班级最高奖励分*100*0.5`;
            title.moral_work_basic = `品德表现测评得分=基本分+奖励分-扣分
奖励分=本人奖励分/班级奖励最高分*100*0.4`;
            title.ability_work_basic = `能力表现测评得分=基本分+奖励分
奖励分=本人奖励分/班级最高奖励分*100*0.5`;
            data_list_new.push(title);

            title = { ...fieldKey_bz };
            data_list_new.push(title);
            for (let i = 0; i < data_students.length; i++) {
              // 初始化数据
              let obj = { ...empty_data };
              obj.student_name = data_students[i].name;
              obj.student_number = data_students[i].id;
              data_list_new.push(obj);
              

              // 文体减分
              // 追加姓名
              let obj_new = {...empty_data_work_del};
              obj_new.student_name = data_students[i].name;
              obj_new.student_number = data_students[i].id;
              
              school_work_del.push(obj_new)
            
              // 文体减分/加分
              let obj_news={...obj_new};
              sport_work_del.push(obj_news)

              // 学历奖励加分
              obj_news={...obj_new};
              school_work_add.push(obj_news)

              
              obj_news={...obj_new};
              sport_work_add.push(obj_news)

              // 品德减分/加分
              obj_news={...obj_new};
              moral_work_del.push(obj_news)

              obj_news={...obj_new};
              moral_work_add.push(obj_news)

              // 能力加分
              obj_news={...obj_new};
              ability_work_add.push(obj_news)


            }
       

            // 合成表(从第一条数据开始)
            for (let i = 1; i < data_list.length; i++) {
              let arr = data_list[i];



              // 多项人员处理
              if (arr[fieldKey.B].indexOf(", ") !== -1) {
                // 分割arr[fieldkey.B]字符串
                const result = arr[fieldKey.B].split(", ");
                // 循环人员
                for (let j = 0; j < result.length; j++) {
                  // 初始化数据
                  let obj = { ...empty_data };
                  // 得到人员姓名
                  const item = result[j];
                  obj[obj_bz.student_name] = item;

                  // 多项处理
                  let brr = {
                    ...arr
                  }
                
                  brr[fieldKey.B] = item;
                  type_work_del(brr)
               


                  // 得到人员所需的变量
                  let obj_new = getScoreList(arr, obj);
                  obj = { ...obj_new.information };
                  // 判断是否存在此人  将数据添加到data_list_new
                  let exist = isExist(data_list_new, item, obj);
                  let show = exist.show;
                  data_list_new = exist.data;
                  // 如果不存在
                  if (!show) data_list_new.push(obj);
                }
              } else {
                // 学业表格扣分处理
                type_work_del(arr)
            

                // 初始化数据
                let obj = { ...empty_data };
                //单项人员处理
                obj[obj_bz.student_name] = arr[fieldKey.B];
                let obj_new = getScoreList(arr, obj);
                obj = { ...obj_new.information };

                // 判断是否存在此人 将数据添加到data_list_new
                let exist = isExist(
                  data_list_new,
                  obj[obj_bz.student_name],
                  obj
                );
                let show = exist.show;
                data_list_new = exist.data;
                // 如果不存在
                if (!show) data_list_new.push(obj);
              }
            }
          
            // 分值处理
            getCalculate(data_list_new);
            exportDataTest(data_list_new);
          }
        );
      } catch (e) {
        layer.alert(e.message);
      }
    }

    //upload上传实例
    var uploadInst = upload.render({
      elem: "#LAY-excel-upload", //绑定元素
      url: "/upload/", //上传接口（PS:这里不用传递整个 excel）
      auto: false, //选择文件后不自动上传
      accept: "file",
      choose: function (obj) {
        // 选择文件回调
        var files = obj.pushFile();
        var fileArr = Object.values(files); // 注意这里的数据需要是数组，所以需要转换一下

        // 用完就清理掉，避免多次选中相同文件时出现问题
        for (var index in files) {
          if (files.hasOwnProperty(index)) {
            delete files[index];
          }
        }
        $("#LAY-excel-upload").next().val("");

        uploadExcel(fileArr); // 如果只需要最新选择的文件，可以这样写： uploadExcel([files.pop()])
      },
    });

    $(function () {
      // 监听上传文件的事件
      $("#LAY-excel-import-excel").change(function (e) {
        // 注意：这里直接引用 e.target.files 会导致 FileList 对象在读取之前变化，导致无法弹出文件
        var files = Object.values(e.target.files);
        uploadExcel(files);
        // 变更完清空，否则选择同一个文件不触发此事件
        e.target.value = "";
      });
      // 文件拖拽
      document.body.ondragover = function (e) {
        e.preventDefault();
      };
      document.body.ondrop = function (e) {
        e.preventDefault();
        var files = e.dataTransfer.files;
        uploadExcel(files);
      };
      // 2019-08-17 页面直接展示所有demo
      renderDemoList();
    });
  }
);

/**
 * 上传excel的处理函数，传入文件对象数组
 * @param  {[type]} files [description]
 * @return {[type]}       [description]
 */
function uploadExcel(files) {
  layui.use(["excel", "layer"], function () {
    var excel = layui.excel;
    var layer = layui.layer;
    try {
      excel.importExcel(
        files,
        {
          // 读取数据的同时梳理数据
          fields: {
            id: "A",
            username: "B",
            experience: "C",
            sex: "D",
            score: "E",
            city: "F",
            classify: "G",
            wealth: "H",
            sign: "I",
          },
        },
        function (data) {
          // 还可以再进行数据梳理
          /*						data = excel.filterImportData(data, {
                'id': 'A'
                ,'username': 'B'
                ,'experience': 'C'
                ,'sex': 'D'
                ,'score': 'E'
                ,'city': 'F'
                ,'classify': 'G'
                ,'wealth': 'H'
                ,'sign': 'I'
              });
        */
          // 如果不需要展示直接上传，可以再次 $.ajax() 将JSON数据通过 JSON.stringify() 处理后传递到后端即可
          layer.open({
            title: "文件转换结果",
            area: ["800px", "400px"],
            tipsMore: true,
            content: laytpl($("#LAY-excel-export-ans").html()).render({
              data: data,
              files: files,
            }),
            success: function () {
              element.render("tab");
              layui.code({});
            },
          });
        }
      );
    } catch (e) {
      layer.alert(e.message);
    }
  });
}

/**
 * 导出数据的测试
 * @return {[type]} [description]
 */
function exportDataByUser() {
  layui.use(["layer"], function () {
    layer.ready(function () {
      layer.prompt(
        {
          title: "请输入测试数据量(9列)",
          value: 3000,
        },
        function (value, index, elem) {
          // 使用setTimeout、async、ajax等方式可以实现异步导出
          setTimeout(function () {
            var num = parseInt(value);
            var timestart = Date.now();
            exportDataTest(num);
            var timeend = Date.now();

            var spent = (timeend - timestart) / 1000;
            layer.alert("耗时 " + spent + " s");
          }, 0);
          layer.close(index);
        }
      );
    });
  });
}

/**
 * 导出接口数据的样例
 * @return {[type]} [description]
 */
function exportApiDemo(url) {
  layui.use(["jquery", "excel", "layer"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var excel = layui.excel;

    // 模拟从后端接口读取需要导出的数据
    $.ajax({
      url: url,
      dataType: "json",
      success: function (res) {
        var data = res.data;
        // 重点！！！如果后端给的数据顺序和映射关系不对，请执行梳理函数后导出
        data = excel.filterExportData(data, {
          id: "id",
          username: "username",
          experience: "experience",
          sex: "sex",
          score: function (value, line, data, lineIndex, newField) {
            // 可以直接指定类型为数字
            return {
              v: value,
              t: "n",
            };
          },
          city: function (value, line, data, lineIndex, newField) {
            return {
              v: value,
              s: {
                font: { sz: 14, bold: true, color: { rgb: "FFFFAA00" } },
                fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FFFF00" } },
              },
            };
          },
          classify: "classify",
          wealth: "wealth",
          sign: "sign",
        });
        // 重点2！！！一般都需要加一个表头，表头的键名顺序需要与最终导出的数据一致
        data.unshift({
          id: "ID",
          username: "用户名",
          experience: "积分",
          sex: "性别",
          score: "评分",
          city: "城市",
          classify: "职业",
          wealth: "财富",
          sign: "签名",
        });

        var timestart = Date.now();
        excel.exportExcel(
          {
            sheet1: data,
          },
          "导出接口数据.xlsx",
          "xlsx"
        );
        var timeend = Date.now();

        var spent = (timeend - timestart) / 1000;
        layer.alert("单纯导出耗时 " + spent + " s");
      },
      error: function () {
        layer.alert("获取数据失败，请检查是否部署在本地服务器环境下");
      },
    });
  });
}

// 样式自定义
function exportDataByStyle(value) {
  let style = {};
  // 头部
  if (value == "a") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
      },
      font: { sz: 36, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "a9cd90" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  // 二级头
  if (value == "b") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
      },
      font: { sz: 28, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "a9cd90" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  // 三级头
  if (value == "c") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
        wrapText: true,
      },
      font: { sz: 28, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "ffc000" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  if (value == "d") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
        wrapText: true,
      },
      font: { sz: 28, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "00b0f0" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  if (value == "e") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
        wrapText: true,
      },
      font: { sz: 28, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "ffd965" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  if (value == "f") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
        wrapText: true,
      },
      font: { sz: 28, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "ffff00" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }
  if (value == "g") {
    return (style = {
      alignment: {
        horizontal: "center",
        vertical: "center",
      },
      font: { sz: 12, bold: true, color: { rgb: "000000" } },
      fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
      border: {
        top: { style: "thin", color: "000000" },
        bottom: { style: "thin", color: { rgb: "000000" } },
        left: { style: "thin", color: { rgb: "000000" } },
        right: { style: "thin", color: { rgb: "000000" } },
      },
    });
  }

  return (style = {
    alignment: {
      horizontal: "center",
      vertical: "center",
    },
    font: { sz: 12, bold: true, color: { rgb: "000000" } },
    fill: {
      bgColor: { indexed: 64 },
      fgColor: { rgb: "a9cd90" },
      color: { rgb: "FFFF0000" },
      edgecolor‌: { rgb: "FFFF0000" },
    },
    border: {
      top: { style: "thin", color: "000000" },
      bottom: { style: "thin", color: { rgb: "000000" } },
      left: { style: "thin", color: { rgb: "000000" } },
      right: { style: "thin", color: { rgb: "000000" } },
    },
  });
}

/**
 * 导出 total 数据测试  （综测表）
 * @param  {[type]} total [description]
 * @return {[type]}       [description]
 */
function exportDataTest(total) {
  layui.use(["excel"], function () {
    var excel = layui.excel;
    // 如果数据量特别大，最好直接传入 AOA 数组，减少内存/CPU消耗
    var data = total;
    // 构造结构
    data = total;
    // 如下代码表示合并 A1~E1 行，并且合并 A2~D4行，如果有动态合并列的需求，请使用 JS 循环生成参数传入
    var mergeConf = excel.makeMergeConfig([
      ["A1", "AA1"],

      ["A2", "AA2"],

      ["A3", "B3"],
      ["C3", "I3"],
      ["J3", "O3"],
      ["P3", "U3"],
      ["V3", "Z3"],

      ["A4", "B4"],
      ["C4", "I4"],
      ["J4", "O4"],
      ["P4", "U4"],
      ["V4", "Z4"],
    ]);

    //如果想动态的传入范围 A1:C{数据长度}，可以将第二个参数改为 'A1:C'+data.length
    // 2. 调用设置样式的函数，传入设置的范围，支持回调
    excel.setExportCellStyle(
      data,
      "A1:AA" + data.length,
      {
        s: {
          fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
          alignment: {
            horizontal: "center",
            vertical: "center",
          },
        },
      },
      function (cell, newCell, row, config, currentRow, currentCol, fieldKey) {
        // 回调参数，
        //cell:原有数据，
        //newCell:根据批量设置规则自动生成的样式，

        //row:所在行数据，config:传入的配置,
        //currentRow:当前行索引,
        //currentCol:当前列索引，
        //fieldKey:当前字段索引

        let sty_cell = {
          v: cell,
          s: exportDataByStyle(),
        };

        newCell = {
          v: newCell.v,
          s: exportDataByStyle("a"),
        };
        if (currentRow == 0) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("a"),
          };
        }

        if (currentRow == 1) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("b"),
          };
        }
        if (currentRow > 1 && currentCol >= 2 && currentCol <= 8) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("c"),
          };
        }
        if (currentRow > 1 && currentCol >= 9 && currentCol <= 14) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("d"),
          };
        }
        if (currentRow > 1 && currentCol >= 15 && currentCol <= 20) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("e"),
          };
        }
        if (currentRow > 1 && currentCol >= 21 && currentCol < 26) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("f"),
          };
        }
        if (currentRow > 1 && currentCol == 26) {
          newCell = {
            v: newCell.v,
            s: exportDataByStyle("g"),
          };
        }
        if (currentRow > 2) {
          newCell.s.font.sz = 10;
        }
        if (currentRow > 3) {
          newCell.s.font.sz = 14;
        }
        if (currentRow > 4) {
          newCell.s.font.sz = 12;
        }

        return newCell;

        // if (currentRow == 4) return newCell;
        // return sty_cell;

        return (currentRow + currentCol) % 2 === 0 ? newCell : newCell; // 隔行隔列上色
      }
    );

    // excel.setExportCellStyle(
    //   school_work_del,
    //   "A1:W" + school_work_del.length,
    //   {
    //     s: {
    //       fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
    //       alignment: {
    //         horizontal: "center",
    //         vertical: "center",
    //       },
    //     },
    //   },
    //   function (cell, newCell, row, config, currentRow, currentCol, fieldKey) {
      
    //   }
    // )
    // excel.setExportCellStyle(
    //   moral_work_add,
    //   "A1:W" + moral_work_add.length,
    //   {
    //     s: {
    //       fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
    //       alignment: {
    //         horizontal: "center",
    //         vertical: "center",
    //       },
    //     },
    //   },
    //   function (cell, newCell, row, config, currentRow, currentCol, fieldKey) {
    //     // row 行 col列
    //     // 回调参数，
    //     //cell:原有数据，
    //     //newCell:根据批量设置规则自动生成的样式，

    //     //row:所在行数据，config:传入的配置,
    //     //currentRow:当前行索引,
    //     //currentCol:当前列索引，
    //     //fieldKey:当前字段索引
    //     if(currentRow > 1 && currentCol >2 && cell!=''){
    //       return newCell = {
    //         v: newCell.v,
    //         s: exportDataByStyle("g"),
    //       };
    //     }
    //   }
    // )

    // 意思是：1行40，2行80(被设置了默认列宽)，3行120px，4/5/6/7等行均未定义（表格默认行宽，非80），1大约对应 1.1磅，由底层控制了，并未在上层封装的时候更改其单位
    var rowConf = excel.makeRowConfig(
      {
        1: 40,
        3: 50,
        4: 50,
      },
      80
    );
    // let ars = [];
    excel.exportExcel(
      {
        综测表: data,
        学业奖励加分:school_work_add,
        学业扣分:school_work_del,
        文体扣分: sport_work_del,
        文体加分:sport_work_add,
        品德加分:moral_work_add,
        品德扣分:moral_work_del,
        能力加分:ability_work_add
      },
      // "测试导出" + total.length + "条数据.xlsx",
      "综测表.xlsx",
      "xlsx",
      {
        extend: {
          综测表: {
            // 需传入生成好的配置信息
            "!merges": mergeConf,
            "!rows": rowConf,
          },
          学业扣分:{

          }
        },
      }
    );
  });
}

/**
 * 导出复杂表头数据问题
 * @return {[type]} [description]
 */
function exportExtendDemo() {
  layui.use(["excel"], function () {
    var excel = layui.excel;
    var data = [
      {
        id: "标志位",
        username: {
          v: "用户信息",
          s: {
            alignment: {
              horizontal: "center",
              vertical: "center",
            },
            fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
          },
        },
        age: "",
        sex: "",
        score: "",
        classify: "",
      }, // 被合并的列数据也需要填充上
      {
        id: "ID",
        username: "基础信息",
        age: "",
        sex: "",
        score: "扩展数据",
        classify: "",
      },
      {
        id: "id",
        username: "用户名",
        age: "年龄",
        sex: "性别",
        score: "积分",
        classify: "职业",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
      {
        id: 1,
        username: "wang",
        age: 10,
        sex: "男",
        score: 100,
        classify: "程序猿",
      },
    ];
    // 生成配置的辅助函数，返回结果作为扩展功能的配置参数传入即可
    // 1. 复杂表头合并[B1,C1,D1][E1,F1]
    var mergeConf = excel.makeMergeConfig([
      ["B1", "F1"],
      ["B2", "D2"],
      ["E2", "F2"],
    ]);
    // 2. B列宽 150，F列宽200，默认80
    var colConf = excel.makeColConfig(
      {
        B: 150,
        F: 200,
      },
      80
    );
    // 3. 第1行行高40，第二行行高30，默认20
    var rowConf = excel.makeRowConfig(
      {
        1: 40,
        3: 30,
      },
      20
    );
    // 4. 公式的用法
    data.push({
      id: "",
      username: "总年龄",
      age: { t: "n", f: "SUM(C4:C10)" },
      sex: "总分",
      score: { t: "n", f: "SUM(E4:E10)" },
      classify: {
        v: "注意：保护模式中公式无效，请「启用编辑」",
        s: { font: { color: { rgb: "FF0000" } } },
      },
    });
    excel.exportExcel(
      {
        sheet1: data,
        sheet2: data,
      },
      "测试导出复杂表头.xlsx",
      "xlsx",
      {
        extend: {
          // extend 中可以指定某个 sheet 的属性，如果不指定 sheet 则所有 sheet 套用同一套属性
          sheet1: {
            "!merges": mergeConf,
            "!cols": colConf,
            "!rows": rowConf,
          },
        },
      }
    );
  });
}

/**
 * 快速设置样式使用方法
 */
function exportStyleDemo() {
  layui.use(["excel"], function () {
    var excel = layui.excel;
    var data = [
      {
        username: "520",
        sex: "男",
        city: "J",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "女",
        city: "X",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
      {
        username: "520",
        sex: "男",
        city: "上海",
        score: 100,
        start: "2019-03-11",
      },
    ]; // 假设的后台的数据
    // 1. 使用filter梳理一下
    data = excel.filterExportData(data, {
      name: "username",
      sex: "sex",
      score: "score",
      start: "start",
      // 这里设置的样式会被合并
      city: function (value) {
        return {
          v: value,
          s: {
            font: { sz: 14, bold: true, color: { rgb: "FFFFAA00" } },
            alignment: {
              horizontal: "center",
              vertical: "center",
            },
          },
        };
      },
      start2: "start",
      score2: "score",
      sex2: "sex",
      name2: "username",
    });
    // 笔芯彩蛋（JeffreyWang 2019-03-11）
    var heart = [
      [0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 1, 1, 0, 1, 1, 0, 0],
      [0, 1, 1, 1, 1, 1, 1, 1, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1],
      [0, 1, 1, 1, 1, 1, 1, 1, 0],
      [0, 0, 1, 1, 1, 1, 1, 0, 0],
      [0, 0, 0, 1, 1, 1, 1, 0, 0],
      [0, 0, 0, 0, 1, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0],
    ];
    // 2. 调用设置样式的函数，传入设置的范围，支持回调
    excel.setExportCellStyle(
      data,
      "A1:I10",
      {
        s: {
          fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FF0000" } },
          alignment: {
            horizontal: "center",
            vertical: "center",
          },
        },
      },
      function (cell, newCell, row, config, currentRow, currentCol, fieldKey) {
        // 回调参数，cell:原有数据，newCell:根据批量设置规则自动生成的样式，row:所在行数据，config:传入的配置,currentRow:当前行索引,currentCol:当前列索引，fieldKey:当前字段索引
        // return ((currentRow + currentCol) % 2 === 0) ? newCell : cell;// 隔行隔列上色
        return heart[currentRow] && heart[currentRow][currentCol]
          ? newCell
          : cell; // 根据阵列，给心形上色
        // return newCell;
      }
    );
    // console.log(data);
    // 3. 单元格样式优化为正方形
    var colConfig = excel.makeColConfig(
      {
        A: 80,
        I: 80,
      },
      80
    );
    var rowConfig = excel.makeRowConfig(
      {
        1: 40,
        10: 40,
      },
      40
    );
    excel.exportExcel(data, "批量设置样式.xlsx", "xlsx", {
      extend: {
        "!cols": colConfig,
        "!rows": rowConfig,
      },
    });
  });
}

/**
 * 加群交流弹窗
 * @return {[type]} [description]
 */
function groupAdd() {
  layui.use(["laytpl", "layer", "jquery"], function () {
    var laytpl = layui.laytpl;
    var layer = layui.layer;
    var $ = layui.jquery;

    var content = laytpl($("#LAY-excel-group-add").html()).render({});
    layer.open({
      title: "加群交流",
      area: ["300px", "450px"],
      content: content,
    });
  });
}

function getDemoListContent(callback) {
  layui.use(["laytpl", "jquery"], function () {
    var laytpl = layui.laytpl;
    var $ = layui.jquery;

    var list = [
      {
        href: "demos/imageExport/index.html",
        path: "demos/imageExport/index.html",
        person: "Sight-wcg",
        email: "https://github.com/Sight-wcg",
        desc: "图片导出的 DEMO",
      },
      {
        href: "demos/tableExport/index.html",
        path: "demos/tableExport/index.html",
        person: "雨桐",
        email: "yuton.yao@qq.com",
        desc: "导出表格数据的DEMO",
      },
      {
        href: "https://kingxjs.github.io/layui-excel-merge/",
        path: "kingxjs.github.io/layui-excel-merge/",
        person: "kingxjs",
        email: "未知",
        desc: "layui 表格中的复杂表头导出",
      },
      {
        href: "demos/noLayui/index.html",
        path: "demos/noLayui/index.html",
        person: "藏锋入鞘",
        email: "admin@wj2015.com",
        desc: "非LAYUI调用及原生表格导出",
      },
      {
        href: "demos/borderExport/index.html",
        path: "demos/borderExport/index.html",
        person: "藏锋入鞘",
        email: "admin@wj2015.com",
        desc: "边框设置DEMO",
      },
      {
        href: "demos/iframeExport/index.html",
        path: "demos/iframeExport/index.html",
        person: "藏锋入鞘",
        email: "admin@wj2015.com",
        desc: "iframe子页面调用导出",
      },
      {
        href: "demos/timeHandle/index.html",
        path: "demos/timeHandle/index.html",
        person: "藏锋入鞘",
        email: "admin@wj2015.com",
        desc: "时间的导入导出控制",
      },
    ];
    var content = laytpl($("#LAY-excel-demo-list").html()).render({
      list: list,
    });
    if (typeof callback == "function" && callback.apply) {
      callback.apply(window, [content]);
    }
  });
}

/**
 * 弹窗弹出demo列表
 */
function demoList() {
  getDemoListContent(function (content) {
    layui.use(["layer"], function () {
      var layer = layui.layer;

      layer.open({
        title: "使用样例",
        area: ["800px", "250px"],
        content: content,
      });
    });
  });
}

/**
 * 页面上直接展示demo列表
 */
function renderDemoList() {
  layui.use(["jquery"], function () {
    var $ = layui.jquery;
    getDemoListContent(function (content) {
      $("#LAY-excel-demo-list-dom").html(content);
    });
  });
}

/**
 * 返回人员加分/减分情况
 * 以及分值
 */
function getScoreList(data, information) {
  // 创建类型变量 加分0 减分1
  let type = 0;
  switch (data[fieldKey.D]) {
    case "加分":
      type = 0;
      break;
    case "减分":
      type = 1;
      break;
  }
  // 创建分值
  let score = Number(0);
  // 创建项目变量
  let project = "";
  // 项目分类
  let classify = "";
  switch (data[fieldKey.C]) {
    case "品德":
      project = data[fieldKey.G];
      score = parseFloat(parseFloat(data[fieldKey.H]).toFixed(2));
      classify = 0; // 品德
      if (type) {
        //减分
        information.moral_work_deduct = score;
      } else {
        //加分

        information.moral_work_award = score;
      }
      break;
    case "学业":
      project = data[fieldKey.I];
      score = parseFloat(parseFloat(data[fieldKey.J]).toFixed(2));
      classify = 1; // 学业
      if (type) {
        //减分
        information.school_work_deduct = score;
      } else {
        //加分
        information.school_work_award = score;
      }
      break;
    case "文体":
      project = data[fieldKey.K];
      score = parseFloat(parseFloat(data[fieldKey.L]).toFixed(2));
      classify = 2; //文体
      if (type) {
        //减分
        information.sport_work_deduct = score;
      } else {
        //加分
        information.sport_work_award = score;
      }
      break;
    case "能力":
      project = data[fieldKey.M];
      score = parseFloat(parseFloat(data[fieldKey.N]).toFixed(2));
      classify = 3; //能力
      //加分
      information.ability_work_award = score;
      break;
    default:
  }

  let obj = {
    type: type, //加分0 减分1
    project: project, //项目
    score: score, //分值
    classify: classify,
    information: information,
  };

  return obj;
}

/**
 * 是否已存在表单提交记录
 */
function isExist(data, item, obj) {
  let show = false;
  for (let p = 0; p < data.length; p++) {
    // 判断是否存在item
    if (data[p][obj_bz.student_name] == item) {
      // 存在
      show = true;
      data[p][obj_bz.school_work_award] += obj[obj_bz.school_work_award];
      data[p][obj_bz.school_work_deduct] += obj[obj_bz.school_work_deduct];

      data[p][obj_bz.sport_work_award] += obj[obj_bz.sport_work_award];
      data[p][obj_bz.sport_work_deduct] += obj[obj_bz.sport_work_deduct];

      data[p][obj_bz.moral_work_award] += obj[obj_bz.moral_work_award];
      data[p][obj_bz.moral_work_deduct] += obj[obj_bz.moral_work_deduct];

      data[p][obj_bz.ability_work_award] += obj[obj_bz.ability_work_award];
      break;
    }
  }
  return {
    data: data,
    show: show,
  };
}

// 分值处理方法
function getCalculate(data) {
  for (let i = 5; i < data.length; i++) {
    // - data[i][obj_bz.moral_work_deduct];
    // 品德分
    let pd_score =
      data[i][obj_bz.moral_work_award] 
    //  - data[i][obj_bz.ability_work_deduct];
    // 学业分
    let xy_score =
      data[i][obj_bz.school_work_award]
    // - data[i][obj_bz.sport_work_deduct];
    // 文体分
    let wt_score =
      data[i][obj_bz.sport_work_award] 
    // - data[i][obj_bz.ability_work_deduct];
    // 能力分
    let nl_score =
      data[i][obj_bz.ability_work_award] 
    // 找到最高分 || 赋值 最高分
    if (type_max_list.school_work <= xy_score) {
      type_max_list.school_work = xy_score;
    }
    if (type_max_list.sport_work <= wt_score) {
      type_max_list.sport_work = wt_score;
    }
    if (type_max_list.moral_work <= pd_score) {
      type_max_list.moral_work = pd_score;
    }
    if (type_max_list.ability_work <= nl_score) {
      type_max_list.ability_work = nl_score;
    }
  }
  console.log(type_max_list);


  for (let i = 5; i < data.length; i++) {
    let item = data[i];
    // 设置最高分
    item.school_work_award_total = type_max_list.school_work;
    item.sport_work_award_total = type_max_list.sport_work;
    item.moral_work_award_total = type_max_list.moral_work;
    item.ability_work_award_total = type_max_list.ability_work;

    // 学业
  
    // item.school_work_total = 
    //   item.school_work_basic +
    //   item.school_work_award_practical -
    //   item.school_work_deduct;
    // 优化后的学业
    item.school_work_basic = 0;
    
    if(item.school_work_award == item.school_work_award_total && item.school_work_award==0){
      item.school_work_award_practical = 0;
    }else if(item.school_work_award == item.school_work_award_total){
      item.school_work_award_practical = 10.00;
    }else{
       // 计算并保留三位小数
       let result = parseFloat(
         (
           (item.school_work_award / item.school_work_award_total) *
           100 *
           0.1
         ).toFixed(3)
       );
       if(!result)result=0;
  
       item.school_work_award_practical = result;
    }
 
    item.school_work_total = (
      item.school_work_basic +
      item.school_work_award_practical -
      item.school_work_deduct
    ).toFixed(3);
    

    // 设置公式
    // 文体
    item.sport_work_basic = 50.0;
    if (item.sport_work_award == item.sport_work_award_total) {
      item.sport_work_award_practical = 50.0;
    } else {
      // 计算并保留三位小数
      const result = parseFloat(
        (
          (item.sport_work_award / item.sport_work_award_total) *
          100 *
          0.5
        ).toFixed(3)
      );
      item.sport_work_award_practical = result;
    }
    item.sport_work_total = (
      item.sport_work_basic +
      item.sport_work_award_practical -
      item.sport_work_deduct
    ).toFixed(3);

    // 品德
    item.moral_work_basic = 60.0;
    if (item.moral_work_award == item.moral_work_award_total) {
      item.moral_work_award_practical = 40.0;
    } else {
      // 计算并保留三位小数
      const result = parseFloat(
        (
          (item.moral_work_award / item.moral_work_award_total) *
          100 *
          0.4
        ).toFixed(3)
      );
      item.moral_work_award_practical = result;
    }
    item.moral_work_total = (
      item.moral_work_basic +
      item.moral_work_award_practical -
      item.moral_work_deduct
    ).toFixed(3);

    // 能力
    item.ability_work_basic = 50.0;
    if (item.ability_work_award == item.ability_work_award_total) {
      if (item.ability_work_award_total != 0) {
        item.ability_work_award_practical = 50.0;
      } else {
        item.ability_work_award_practical = 0;
      }
    } else {
      // 计算并保留三位小数
      const result = parseFloat(
        (
          (item.ability_work_award / item.ability_work_award_total) *
          100 *
          0.5
        ).toFixed(3)
      );
      item.ability_work_award_practical = result;
    }
    item.ability_work_total = (
      item.ability_work_basic + item.ability_work_award_practical
    ).toFixed(3);

    // 综测总分
    const result_s = parseFloat(
      (
        item.school_work_total * 0.65 +
        item.sport_work_total * 0.1 +
        item.moral_work_total * 0.15 +
        item.ability_work_total * 0.1
      ).toFixed(3)
    );
  

    item.total = result_s;
  }
  let desc_data = data.slice(5);
  desc_data = insertionSortDescending(desc_data);

  for (let i = 5; i < data.length; i++) {
    data[i] = desc_data[i - 5];
  }
}

// 插入排序
function insertionSortDescending(arr) {
  const n = arr.length;
  for (let i = 1; i < n; i++) {
    const current = arr[i];
    let j = i - 1;

    // 将小于 current 的元素向后移动
    while (j >= 0 && arr[j].total < current.total) {
      arr[j + 1] = arr[j];
      j--;
    }

    // 将 current 插入到正确的位置
    arr[j + 1] = current;
  }

  return arr;
}
